package factory;
import java.util.List;
import dao.Impldao;
import dao.Userdao;
import entity.User;
public class IEmpDAOProxy implements Userdao{
	
    private Userdao  dao=null;  //声明DAO对象  
    public IEmpDAOProxy()throws Exception{ //在构造方法中实例化连接，同时实例化dao对象  
        
        dao=new Impldao();//实例化真实主题类  
    }  
    public boolean add(User user)throws Exception{  
        boolean flag=false; //定义标志位  
        try{  
            if(!(this.dao.find(user.getUsername()))){//如果要插入的用户不存在  
                flag=this.dao.add(user);//调用真实主题操作  
            }  
        }catch(Exception e){  
            throw e;  
        } 
        return flag;  
    }  
    public List<User>findall()throws Exception{  
        List<User> all=null;  //定义返回的集合  
        try{  
            all=this.dao.findall();//调用真实主题  
        }catch(Exception e){  
            throw e;  
        } 
        return all;       
    }  
    public boolean find(String username)throws Exception{  
    	boolean flag=false;  
        try{  
            flag=this.dao.find(username);  
        }catch(Exception e){  
            throw e;  
        } 
        return flag;  
    }  



	public boolean delete(User user) throws Exception {
		boolean flag=false;  
        try{  
            flag=this.dao.delete(user);  
        }catch(Exception e){  
            throw e;  
        } 
        return flag;  
	}

	public boolean update(User user) throws Exception {
		boolean flag=false;  
        try{  
            flag=this.dao.update(user);  
        }catch(Exception e){  
            throw e;  
        } 
        return flag;
	}

	public User findid(String username) throws Exception {
		User user=null;
		try{
			user=this.dao.findid(username);
		}catch(Exception e){  
            throw e; 
	}
		return user;
	}

}
